package com.ycx.ycxmybatismanagement.service.Impl;

import com.ycx.ycxmybatismanagement.aop.MyLog;
import com.ycx.ycxmybatismanagement.dto.DtoDept;
import com.ycx.ycxmybatismanagement.mapper.DeptMapper;
import com.ycx.ycxmybatismanagement.pojo.Dept;
import com.ycx.ycxmybatismanagement.service.DeptService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiveImpl implements DeptService {
    @Autowired
    DeptMapper deptMapper;

    /**
     * 查询
     * @return
     */
    @Override
    public List<Dept> deptList() {
       List<Dept> deptList= deptMapper.deptList();
       return deptList;
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void deleteDept(int id) {
        deptMapper.deleteDept(id);
    }

    /**
     * 添加
     * @param dtoDept
     */
    @Override
    public void insertDept(DtoDept dtoDept) {
        Dept dept = new Dept();
        dept.setName(dtoDept.getName());
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insertDept(dept);
    }

    /**
     * 回显
     * @param id
     * @return
     */
    @Override
    public Dept selectDept(Integer id) {
     Dept dept = deptMapper.selectDeptById(id);
     return dept;
    }

    /**
     * 修改
     * @param dtoDept
     */
    @Override
    public void updateDept(DtoDept dtoDept) {
        Dept dept = new Dept();
        BeanUtils.copyProperties(dtoDept,dept);
        deptMapper.updateDept(dept);
    }
}
